<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
$(function(){
    $("#gridTable").jqGrid({
        url:'${request.contextPath}/list!list.action',
        datatype: "json",
        mtype:"POST",
        height: 1000,
        width: 1000,
        colNames:['用户编号','船舶编号','状态','创建人','创建日期','最后修改人','最后修改日期'],
        colModel:[
                    {name:'userId',jsonmap:'USER_ID',index:'USER_ID',editable:false,hidden:true},
                    {name:'shippingId',jsonmap:'SHIPPING_ID',index:'SHIPPING_ID',editable:false,editrules:{edithidden:true,required:false}},
                    {name:'status',jsonmap:'STATUS',index:'STATUS',editable:true,editrules:{required:true,number:true}},
                    
                    {name:'createdBy',jsonmap:'CREATED_BY',index:'CREATED_BY',editable:true,editrules:{required:true}},
                    {name:'createdDate',jsonmap:'CREATED_DATE',editable:true,editrules:{required:true}
                        editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                    }}     
                    
                    },
                   
                    {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:true,editrules:{required:true}},
                    {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:true,editrules:{required:true},
                              editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                        }}       
                    }
                    
                    ],
        sortname : 'LAST_UPD_DATE',
        sortorder : 'desc',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        multiselect: true,
        autowidth : true,
        editurl: '${request.contextPath}/operator.action',
        rowNum : 20,
        rowList : [10,20,30],
        jsonReader : {
            page : "page.pageNo", //固定名称
            total : "page.totalPages", //固定名称
            records : "page.totalCount", //固定名称
            root : "page.result", //固定名称
            repeatitems : false, //固定
            id : 'CER_ID'
        },
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
        	//设置需要访问的list标签
        	settings.data=settings.data+ "&gridKey=/list#TsmAttention";
            return true;
        }
        pager : "#gridPager",
        caption : "船舶证书列表"
        }).navGrid('#gridPager', {
                edit : false,
                add : false, 
                del : false,
                
                search : false
        }, {  
                //edit
           beforeSubmit:true,
           reloadAfterSubmit : true, 
           closeAfterEdit : true,  //修改完毕后关闭
           afterComplete : opertaionPrompt, //更新结束后提示信息
           onclickSubmit: fillCategoryId
        }, {
                //add
           reloadAfterSubmit : true,
           closeAfterAdd : true, //新增完毕后关闭
           afterComplete : opertaionPrompt
           
       }).navButtonAdd('#gridPager',{
        
           caption:"添加关注",
           buttonicon:"ui-icon-add", 
           onClickButton: function(){
        	   var consoleDlg=$("#gridDialog");
        	   consoleDlg.dialog("option","title","添加船舶关注").dialog("open");
        	   
           }
           
       });
       
    $("#gridDialog").dialog({
    	autoOpen: false,
        model:true,  //设置对话框为模态对话框
        resizable: true,
        width: 500,
        open : function(){
        	var selectedId=$("#gridTable").jqGrid("getGridParm","selrow");
            var displayName=jQuery('#gridTable').jqGrid('getRowData',selectedId).admin_name;
                   
        },
        button: {//为对话框添加按钮
        	"添加":addUser,
        	
        }
    });
   });
var addUser=function(){
	alert("fghuij");
}
   </script>
   <script type="text/javascript">
   var setting = {
            async: {
                enable: true,
                url: '${request.contextPath}/admin/shipTree.action',
                datatype : 'json',
                autoParam:["id","name","pId"]
            },
            data: {
                simpleData: {
                       enable: true
                }
            },
            callback:{
                onClick:zTreeClick
            }
            
        };
   
   function fillCategoryId(params, postdata) {
       var treeObj = $.fn.zTree.getZTreeObj("categoryTree");
       var nodes = treeObj.getSelectedNodes();
       var add_data = new Object();
       add_data["bigtype_code"] = nodes[0].id;
       return add_data;
   }
        function zTreeClick(event,treeId,treeNode){
        var a=treeNode.id;
          a=a.replace("B","");
        //alert(a);
            jQuery("#gridTable").jqGrid('setGridParam',{
                url : "${request.contextPath}/admin/getShipAttrList!list.action?shippingId="+a,
                page : 1 
            });
            jQuery("#gridTable").trigger('reloadGrid');
        }

        jQuery(document).ready(function(){
            $.fn.zTree.init($("#categoryTree"), setting);
        });
        
    $(function(){
        $("#gridTable").jqGrid({
            url:'${request.contextPath}/admin/getShipAttrList!list.action',
            datatype: "json",
            mtype:"POST",
            height: 200,
            width: 1000,
            colNames:['证书ID','船舶ID','证书代码','证书名','开始日期','结束日期','备注','证书类型','状态','创建人','创建日期','最后修改人','最后修改时间','文件'],
            colModel:[
                        {name:'cer_id',jsonmap:'CER_ID',editable:true,hidden:true,editrules:{edithidden:true,required:false}},
                        {name:'shipping_id',jsonmap:'SHIPPING_ID',editable:true,editrules:{edithidden:true,required:false},hidden:true},
                        {name:'cer_code',jsonmap:'CER_CODE',editable:true,editrules:{required:true,number:true}},
                        
                        {name:'cer_name',jsonmap:'CER_NAME',editable:true,editrules:{required:true}},
                        
                        {name:'start_date',jsonmap:'START_DATE',editable:true,editrules:{required:true,data:true},
                               editoptions :  {dataInit: function(element) {
                                $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                            }}               
                        },
                        {name:'end_date',jsonmap:'END_DATE',editable:true,editrules:{required:true},
                                  editoptions :  {dataInit: function(element) {
                                $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                            }}       
                        },
                        {name:'remark',jsonmap:'REMARK',editable:true,editrules:{edithidden:true,required:true},hidden:true},
                        {name:'cre_type',jsonmap:'CRE_TYPE',editable:false,edittype:'select',align:'center',editrules:{required:true},editoptions:{value:{0:'普通证书',1:'保险证书'}},hidden:true},
                        {name:'status',jsonmap:'STATUS',editable:false,edittype:'select',align:'center',editrules:{required:true},editoptions:{value:{0:'有效',1:'无效'}},hidden:true},
                        {name:'created_by',jsonmap:'CREATED_BY',editable:false,editrules:{required:true},hidden:true},
                        {name:'created_date',jsonmap:'CREATED_DATE',editable:false,hidden:true,editrules:{required:true},
                            editoptions :  {dataInit: function(element) {
                                $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                            }}       
                        },
                        {name:'last_upd_by',jsonmap:'LAST_UPD_BY',editable:false,editrules:{required:true},hidden:true},
                        {name:'last_upd_date',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,editrules:{required:true},
                          editoptions :  {dataInit: function(element) {
                                $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                            }}  
                        },
                        {name:'file_url',jsonmap:'FILE_URL',editable:false,hidden:true,editrules:{required:true}},
                        //{name:'gu',index:'index1',label:'更新',align:'center',}
                        
                        
                        ],
            sortname : 'LAST_UPD_DATE',
            sortorder : 'desc',
            viewrecords : true,
            gridview : true,
            rownumbers : true,
            gridComplete: function () {
                var graduateIds = jQuery("#gridTable").jqGrid('getDataIDs');
                for (var i = 0; i < graduateIds.length; i++) {
                    var cl = graduateIds[i];
                    var link = "<a href='login.jsp?'><font color='red'>下载</font></a>";
                    jQuery("#gridTable").jqGrid('setRowData', cl, {file_url: link })
                }
                },
                 
            editurl: '${request.contextPath}/admin/getShipManagementList.action',
            rowNum : 20,
            rowList : [10,20,30],
                 
            jsonReader : {
                page : "page.pageNo", //固定名称
                total : "page.totalPages", //固定名称
                records : "page.totalCount", //固定名称
                root : "page.result", //固定名称
                repeatitems : false, //固定
                id : 'CER_ID'
            },  
            prmNames : {
                rows : "page.pageSize",
                page : "page.pageNo",
                sort : "page.orderBy",
                order : "page.order"
            },
            pager : "#gridPager",
            caption : "船舶证书列表"
            }).navGrid('#gridPager', {
                    edit : true,
                    add : true, 
                    del : true,
                    search : true
            }, {  
                    //edit
               //bSubmit: "Submit",
               //function(){
                 // $("#FrmGrid_gridTable").attr("action","${request.contextPath}/admin/getShipManagementList!uploadFile.action");
                  //$("#FrmGrid_gridTable").attr("method","post");
                   //$("#FrmGrid_gridTable").attr("onsubmit","return:true");
                  //$("#FrmGrid_gridTable").attr("enctype","multipart/form-data");
                  //$("#FrmGrid_gridTable").submit();
                
                //return false;
               //},
               //reloadAfterSubmit : true, 
               beforeSubmit:true,
               reloadAfterSubmit : true, 
               closeAfterEdit : true,  //修改完毕后关闭
               afterComplete : opertaionPrompt, //更新结束后提示信息
               onclickSubmit: fillCategoryId
            }, {
                    //add
               reloadAfterSubmit : true,
               closeAfterAdd : true, //新增完毕后关闭
               afterComplete : opertaionPrompt
           })
       });
        
       function uploadPriceFile(){
           var $fileUploadDiv = $('#fileUploadDiv');
           $fileUploadDiv.html('<div id="fileQueue"></div><input type="file" name="uploadify" id="uploadify"/><p><a id="uploadOper" href="#">上传</a>| <a id="uploadCannelOper" href="#">取消上传</a> <a href="${request.contextPath}/importtemplate/importprice.xls">模板下载</a></p><span id="result" style="color: red"></span>');
           $fileUploadDiv.dialog({
               title : '文件上传',
               height : 300,
               width : 400,
               modal : true,
               open : function() {
                   $('#uploadify').uploadify({
                       'uploader'  : '${request.contextPath}/js/uploadify/uploadify.swf',
                       'scriptData': {},
                       'script'    : '${request.contextPath}/admin/priceUpload!uploadImportFile.action?jsessionid=<%=session.getId()%>',
                       'cancelImg' : '${request.contextPath}/js/uploadify/cancel.png',
                       'folder' : '/uploadFiles',
                       'auto' : false,
                       'multi' : false,
                       'sizeLimit' : 1024000,
                       'fileExt' : '*.xls',
                       'fileDesc' : '请选择xls文件',
                       'queueID' : 'fileQueue',
                       'onComplete' : function(event, queueID, fileObj,
                               response, data) {
                           $('#result')
                                   .html("文件:" + fileObj.name + "上传成功");
                       },
                       'onError' : function(event, queueID, fileObj) {
                           $('#result')
                                   .html("文件:" + fileObj.name + "上传失败");
                       },
                       'onCancel' : function(event, queueID, fileObj) {
                           $('#result').html("取消了" + fileObj.name);
                       }
                   });
                   $("#uploadOper").click(function(){
                       $("#uploadify").uploadifyUpload();
                   });   
                   $("#uploadCannelOper").click(function(){
                       $("#uploadify").uploadifyClearQueue();
                   });    
                   $('#result').html("");
           }
           
           
       });
       }
   
   
   </script>
   </head>
   <body>
   <div id="gridDialog">  
                    <input type="hidden" id="selectId" />  
                    <table id="gridAttentionTable" class="formTable">  
                        <tr>  
                            <th><span class="ui-widget-header">客户名称</span></th>  
                        </tr>  
                    </table>
                    <div id="gridAttentionPager"></div>      
                  
            </div>  
   </body>
   </html>
   